home *** CD-ROM | disk | FTP | other *** search
/ Internet Tools (InfoMagic) / Internet Tools.iso / dos_win / winsock / hacklist / 94-04.Z / 94-04 / 000005_ICH211@ZAM001.Z…KFA-JUELICH.DE_Wed Apr 6 13:24:53 1994.msg < prev    next >
Internet Message Format  |  1994-04-30  |  7KB

  1. Received: from zam001.zam.kfa-juelich.de by SunSITE.Unc.EDU (5.65c+IDA/FvK-1.07) with SMTP
  2.           id AA19461; Wed, 6 Apr 1994 05:40:24 -0400
  3. Message-Id: <199404060940.AA19461@SunSITE.Unc.EDU>
  4. Received: from DJUKFA11 by ZAM001.ZAM.KFA-JUELICH.DE (IBM VM SMTP V2R2)
  5.    with BSMTP id 2542; Wed, 06 Apr 94 11:40:25 +0200
  6. Date:         Wed, 06 Apr 94 11:24:53 +0200
  7. From: Thomas Heil <ICH211@ZAM001.ZAM.KFA-JUELICH.DE>
  8. Organization: Forschungszentrum Juelich GmbH - Institut fuer Chemie 2
  9. Subject:      Re: Closing and reusing sockets
  10. To: Multiple recipients of list <winsock-hackers@sunsite.unc.edu>
  11. In-Reply-To:  Message of Tue, 5 Apr 1994 09:13:03 -0400 from <bryan@alex.com>
  12.  
  13. On Tue, 5 Apr 1994 09:13:03 -0400 you said:
  14. >> From: paul@atlas.abccomp.oz.au
  15. >
  16. >> [loads of stuff -- should one call bind?]
  17. >
  18. >> Now, the twist from your last sentence (above) is that you want to
  19. >> bind() and connect() from a free reserved port - only in this case is
  20. >>                             ---- ======== ----
  21. >> it necessary or recommended to call bind() before connect().
  22. >
  23. >Thanks for this confirmation.
  24. >
  25. >> To avoid WSAEADDRINUSE errors, you must make sure a socket is fully closed
  26. >> before you can connect _from_the_same_port_number_ to the same remote
  27. >> machine listening on the _same_remote_port_ - possibly by blocking in
  28. >> a lingering close, or using linger to hard-close the connection when
  29. >> you're done the first time.
  30. >
  31. >This is roughly what I said in the very first message in this thread --
  32. >hard-closing
  33. >the socket makes the problem go away.  I guess that waiting for the close to
  34. >complete (probably not actually blocking, given that we're all nice cooperative
  35. >Windows programmers) is gentler, but it would complicate the exit logic of the
  36. >program rather a lot.
  37. >
  38. >This would all be a lot easier if we could rely on bind() giving EADDRINUSE
  39. >so that the next port could be used instead, and leave the stack to
  40. >get on with closing down the old one quietly.
  41. >
  42. >Bryan.
  43. >
  44.  
  45. I had the same problem with unreliable bind()s (with FTP Software's Winsock)
  46. in my WLPR.DLL which is used by my LPR client and Windows Spooler. The LPR
  47. protocol demands the client to bind to a free reserved port number, So I
  48. took the sample code from the WinSock specs. The bind() always succeeded,
  49. and the connect() bombed with EADDRINUSE when there was an older connection
  50. lingering. So I put a linger(1,0) before the closesocket() call. This forced
  51. the connections to close completely, but it had the nasty side effect to
  52. give the LPR server a "connection reset" error, which caused a lot of
  53. LPDs to die (meaning the spool job went into the queue but was not sent to the
  54. printer).
  55. I got the same reply from FTP Software about "no bind used internally" etc,
  56. which I actually don't find acceptable. I believe that sample code in a
  57. specification should work with all compliant implementations, otherwise the
  58. implementation is *not* specification compliant. Since the FTP Winsock.DLL
  59. surely has access to all pending connection info it should be able to determine
  60. at bind() time if there is a local address in use, and return EADDRINUSE if
  61. necessary. What I had to do in my code is to have the bind() loop followed
  62. by a connect() as it should be, and have another loop around all this to
  63. try a new port if the connect() fails.
  64.  
  65. Just my 2 cents ...
  66.  
  67. /Thomas
  68.  
  69. ---------------------------------------+--------------------------------------
  70. Mail: Thomas Heil                      | EMail: BITNET: ICH211@DJUKFA11.BITNET
  71.       Forschungszentrum Juelich - ICG2 |      Internet: th.heil@kfa-juelich.de
  72.       52425 Juelich                    | Phone: +49 2461 61-6915
  73.       Germany                          | Fax:   +49 2461 61-5346
  74. From bryan%alex.com@gateway.alex.com Wed Apr  6 07:56:40 1994
  75. Received: from post.demon.co.uk by SunSITE.Unc.EDU (5.65c+IDA/FvK-1.07) with SMTP
  76.           id AA01736; Wed, 6 Apr 1994 07:56:40 -0400
  77. Received: from gateway.alex.com by post.demon.co.uk id ab18202;
  78.           6 Apr 94 12:21 GMT-60:00
  79. Return-Path: <bryan@alex.com>
  80. Received: from SKID by woody.alex.com (4.1/SMI-4.1)
  81.     id AA15772; Wed, 6 Apr 94 12:21:39 BST
  82. Date: Wed, 6 Apr 94 12:21:39 BST
  83. Message-Id: <9404061121.AA15772@woody.alex.com>
  84. X-Sender: bryan@alex.com
  85. Mime-Version: 1.0
  86. Content-Type: text/plain; charset="us-ascii"
  87. To: winsock-hackers@sunsite.unc.edu
  88. From: Bryan Boreham <bryan@alex.com>
  89. Subject: Re: Closing and reusing sockets
  90. X-Mailer: <PC Eudora Version 1.4>
  91.  
  92. >From Paul Brooks, paul@abccomp.oz.au:
  93.  
  94. >True, but you still have to think about the case where your local machine
  95. >has closed the socket down OK, allowing you to BIND to the same
  96. >port number in the future, but the REMOTE end still has the same
  97. >port/address association valid, probably in TIMEWAIT state for two minutes.
  98. >
  99. >In this case, your bind() will succeed, but the remote end may well refuse
  100. >the connection. WSAEADDRINUSE is a valid return from connect(),
  101.  
  102. Aha!  I was working on the assumption that EADDRINUSE referred to the
  103. *local* address, not the remote address.  The spec doesn't specify --
  104. is there any other explicit reference?  I see that Stevens "Unix Network 
  105. Programming" does use it as you describe in the rcmd example, page 570.
  106.  
  107. However, exactly the same circumstances didn't result in a failure at all
  108. using the Trumpet stack.  I think I'll do some network sniffing to see if
  109. I can spot what is different.
  110.  
  111. >as well as bind(). Also, if you set the socket option SO_REUSEADDR you will
  112. >be allowed to bind() to the same port number, on the assumption that you want
  113. >to connect to a different host/port from last time. If you try to connect()
  114. >to the same host/port as last time, you'll get back WSAEADDRINUSE from
  115. >connect().
  116.  
  117. This is not what we are doing.
  118.  
  119. >Maybe if you describe what you are actually trying to do to the list,
  120.  
  121. I gave a description in the first instance, but it was perhaps not very 
  122. precise.  The trouble is that we sell a development system, a programming
  123. language, and therefore I have to cover all the cases that can arise when 
  124. third parties use our language to write systems.  I am not asking for 
  125. specific answers to work round one program failure, I am asking about how 
  126. stacks should behave *in* that failure mode.
  127.  
  128. Here is one specifc case: suppose a program uses rsh twice in 
  129. succession, something which is very easy in the Alex language.  We must 
  130. bind to a free reserved port locally, and we must connect to the same 
  131. remote port each time.  We would like to do this reliably on any of
  132. the dozen or more Winsock stacks that our customers might use, with
  133. the minimum of hack work-arounds that "just happen to fix it".
  134.  
  135. >instead of vague references to a private exchange, 
  136.  
  137. I believe I quoted verbatim all references to the private exchange.  
  138.  
  139. >we might be able to help you.
  140.  
  141. It all helps.  Thank you.
  142.  
  143. Bryan.